package com.geek.framework.study.config.microprofile.converter;

import org.eclipse.microprofile.config.spi.Converter;

public abstract class AbstractConverter<T> implements Converter {

    @Override
    public Object convert(String value) throws IllegalArgumentException, NullPointerException {
        if (value == null) {
            throw new NullPointerException("The value must not be null!");
        }
        T convertedValue = null;
        try {
            convertedValue =  doConvert(value);
        } catch (Exception e) {
            throw new IllegalArgumentException();
        }
        return convertedValue;
    }

    protected abstract T doConvert(String value) throws Exception;
}
